import {
  AfterViewInit,
  Component,
  ElementRef,
  OnInit,
  Renderer2, ViewChild, OnDestroy, QueryList, ViewChildren,
} from '@angular/core';
import {ApiService} from '../../../core/services/http/api.service';
import {ApesMessageService} from "../../../shared/apes/message/index";
import {CompanyModalComponent} from "../company-modal/company-modal.component";
import {AnalysisService} from "../analysis.service";
import {UserAuthService} from "@core/services/user-auth.service";
import {Router} from "@angular/router";
import { CarPanelComponent } from '../car-control/car-panel/car-panel.component';
import { CarMinutiaComponent } from '../car-control/car-minutia/car-minutia.component';
import { DatePipe } from '@angular/common';

@Component({
  selector: 'dome-control',
  templateUrl: './dome-control.component.html',
  styleUrls: ['./dome-control.component.scss'],
})
export class DomeControlComponent implements OnInit, AfterViewInit, OnDestroy {
  @ViewChildren(CarPanelComponent) childCmps: QueryList<CarPanelComponent>;
  @ViewChildren(CarMinutiaComponent) childMinutia: QueryList<CarMinutiaComponent>;
  @ViewChild(CompanyModalComponent, { static: true }) child: CompanyModalComponent;
  private timer;
  private timers;
  private remarkTimers;

  // 时间相关
  todayTimes: Date;
  dateTimes: any[] = [];
  months: Date;
  dateMonths: any[] = [];
  // 脑袋汇总
  headList: any[];
  titleData = {};
  // 左侧表
  reportData: any[] = [];
  leftList: any [] = [];
  allData: any[];
  tablesIndex: number = 0;


  // 左侧表头状态
  iconData: any[] = [];
  check: string = '1';

  // 虚拟触发相关
  rightData: any;
  CheckId: any;
  carIcon: any;
  carNum: any;
  mdid: any;
  JCID: string;

  rightList = {};
  topData: any [];
  companyLocal = this.as.getLocalObj();
  companyData = [];
  company: any;
  userInfo = this.userAuthService.getUserInfoObj();
  keyNum: any = 0;
  clickTime: any;
  tracking = [];
  remarkData = [];
  review = [];
  pageRemarks: number = 0;
  jd: string;

  //抽屉相关
  carVisible: boolean = false;
  queryList: any = [];
  radioValue: string = 'CarInTV';
  pickCarTime: any = [];
  carStartTime: Date = null;
  carEndTime: Date = null;
  carNumber: string;
  carStatusId: string;
  carStore = [];
  carStoreId: string;
  damage = [];
  damageId: string;
  carBrands: string;
  checkOne: boolean;
  checkTwo: boolean;
  checkThe: boolean;
  checkFro: boolean;
  setReview: string;
  entryVisible: boolean = false;

  constructor(private apiService: ApiService,
              private el: ElementRef,
              private renderer: Renderer2,
              private msg: ApesMessageService,
              private as: AnalysisService,
              private userAuthService: UserAuthService,
              private router: Router,
              private datePipe: DatePipe) {
    if (this.companyLocal) {
      let company: any = this.companyLocal;
      let data = [];
      for (let item of company) {
        for (let list of item['array']) {
          data.push(list.id);
        }
      }
      this.company = this.as.unique(data);
    } else if (this.userInfo) {
    } else {
      this.router.navigateByUrl('/analysis/control/index');
    }

    this.timers = setInterval(() => {
      this.dateMonths = [];
      this.dateTimes = [];
      this.getMonths();
      this.getTodayTimes();
    }, 1000);
  }

  ngOnInit() {
    this.companyData = this.company;
    this.changeCompany(this.companyData);
  }

  changeCompany(e) {
    this.companyData = e;
    this.getHeadTop();
    this.headList = this.setHeadData();
    this.getLeftData();
    this.leftList = this.getLeftHead();
    this.topData = this.setRightData();
    this.getQueryHead();
    this.getStoreData();
    this.getDamageData();
  }

  ngAfterViewInit() {
    setTimeout(() => {
      this.$('0').focus();
      // this.getCheck();
    }, 2000);
    const content = document.querySelector('#Boxs');
    const _body = document.querySelector('body');
    if (_body.clientWidth > 1920) {
      let _zoom = _body.clientWidth / content.clientWidth;
      setTimeout(() => {
        this.renderer.setStyle(content, 'zoom', _zoom);
      }, 100);
    }
  }

  setClearTime() {
    clearInterval(this.timer);
    clearInterval(this.remarkTimers);
    let times = (1000 * 60) * 10;
    this.timer = setInterval(() => {
      this.tablesIndex = 0;
      this.reportData = [];
      this.allData = [];
      this.titleData = {};
      this.getHeadTop();
      this.getQueryHead();
      this.getLeftData();
    }, times);

    this.remarkTimers = setInterval(() => {
      this.remarkData = [];
      this.remarkData = this.pageRemark(this.review, 2);
    }, 10000);
  }

  // 返回上一页
  goBack($event: any) {
    let key = $event.button;
    if (key === 2) {
      history.go(-1);
      return false;
    }
  }

  getMonths() {
    this.months = new Date();
    this.dateMonths = [];
    let shijian = 0;
    let riqi = 1;
    let newTimes;
    let month = this.months.toTimeString();
    for (let i = 0, len = month.length; i < len; i++) {
      newTimes = month.slice(shijian, riqi);
      this.dateMonths.push(newTimes);
      shijian++;
      riqi++;
    }
    this.dateMonths = this.dateMonths.filter((value) => value !== ':');
  }

  getTodayTimes() {
    this.todayTimes = new Date();
    this.dateTimes = [];
    let shijian = 0;
    let riqi = 1;
    let newTimes;
    let todayTime = this.todayTimes.toISOString();
    for (let i = 0, len = todayTime.length; i < len; i++) {
      newTimes = todayTime.slice(shijian, riqi);
      this.dateTimes.push(newTimes);
      shijian++;
      riqi++;
    }
    this.dateTimes = this.dateTimes.filter((value) => value !== '-');
  }

  // 脑袋汇总
  getHeadTop() {
    let data = { 'interfaceMethod': 'ipmCLZKForAppService.getTVHead', 'pdata': { 'companyId': this.companyData } };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            this.titleData = data[0];
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  setHeadData() {
    return [
      {
        titleData: [
          { lable: '总车辆', feild: 'WJCZCL' },
          { lable: '交车超时', feild: 'CSZCL' },
          { lable: '服务超时', feild: 'FWCSSL' },
          { lable: '定损中', feild: 'DSBJZ' },
          { lable: '待确认', feild: 'DFAQR' },
          { lable: '施工中', feild: 'CLSGZ' },
          { lable: '待质检', feild: 'DZJJS' },
        ],
      },
    ];
  }

  // 左侧表
  getLeftData() {
    let data = {
      'interfaceMethod': 'ipmCLZKForAppService.getLeftTotal',
      'pdata': {
        'JCSJSTART': this.carStartTime, 'JCSJEND': this.carEndTime,
        'CPHM': this.carNumber,
        'JD': this.carStatusId,   // 车辆状态
        'MDID': this.carStoreId,
        'KEY': this.radioValue,  //头部
        'DSZT': this.checkOne,  // 定损车
        'FXCBJ': this.checkTwo,  // 返修车
        'NSCBJ': this.checkThe,   // 年审车
        'SPCBJ': this.checkFro,   // 水泡车
        'DSJDID': this.damageId,     // 定损进度
        'companyId': this.companyData,     // 公司
        'QCCPMC': this.carBrands,     // 汽车厂牌
        // 'GHSJSTART': this.yjjcTime_ks, 'GHSJEND': this.yjjcTime_js,
        // 'XSZID': this.saleID,       // 销售组
        // 'YJCZT': this.checkFor,   // 已交车
        // 'NSJDID': this.annualID,  // 年审进度
        // 'CARPLACEID': this.carID,  // 车在哪
        // 'FWLX': this.ngFWLX,       // 服务类型
      },
    };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            const data = JSON.parse(result.obj);
            for (let i = 0, len = data.length; i < len; i++) {
              if (data[i]['JDCS'] < 0) {
                data[i]['JDCS'] = null;
              }
            }
            this.allData = data.sort(this.sortarr('HJCS', 'down'));
            this.pageList(this.allData);
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  getLeftHead() {
    return [
      {
        tabWidth: 100,
        allleft: [
          { 'headerName': '车牌', width: 12, logo: 'PTLJ' },
          { 'headerName': '', width: 8 },
          { 'headerName': '门店', width: 13 },
          { 'headerName': '车辆状态', width: 10 },
          { 'headerName': '接车时间', width: 11 },
          { 'headerName': '预计交车时间', width: 11 },
          { 'headerName': '总耗时/超时', width: 13 },
        ],
      },
    ];
  }

  // 左侧表头状态
  getIcon() {
    let data = {
      'interfaceMethod': 'ipmCLZKForAppService.getJCJC',
      'pdata': { 'JJCDH': this.CheckId, 'CPHM': this.carNum, 'MDID': this.mdid, 'ZT': this.check },
    };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            const data = JSON.parse(result.obj);
            this.iconData = data;
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  // 分页显示
  pageList(arrData: any[]) {
    this.reportData = [];
    while (arrData.length > 0) {
      let tempArr = arrData.splice(0, 26);
      this.reportData.push(tempArr);
    }
    if (this.reportData.length > 0) {
      this.rightList = this.reportData[0][0];
      this.CheckId = this.reportData[0][0].JJCDH;
      this.carIcon = this.reportData[0][0].TPLJ;
      this.carNum = this.reportData[0][0].CPHM;
      this.mdid = this.reportData[0][0].MDID;
      this.getCheck();
    }
  }

  pageRemark(arrData: any[], page: number) {
    let rowData = [];
    const count = arrData.length;
    let tempIndex = 0;
    for (let i = this.pageRemarks; i < count; i++) {
      if (tempIndex < page) {
        rowData.push(arrData[i]);
      } else {
        break;
      }
      tempIndex++;
      this.pageRemarks++;
    }
    //当数据遍历完 重新请求数据
    if (this.pageRemarks >= count) {
      this.pageRemarks = 0;
    }
    return rowData;
  }

  // 显示 天 时 分 换算
  toHourMinute(minutes) {
    if (Math.floor(minutes / 60 / 24) >= 1) {
      if (Math.floor(minutes / 60 / 24) < 10) {
        return (Math.floor(minutes / 60 / 24) + '天');
      }
      return (Math.floor(minutes / 60 / 24) + '天');
    } else if (Math.floor(minutes / 60 / 24) < 1) {
      if (Math.floor(minutes) < 60) {
        if (Math.floor(minutes) === 0) {
          return '';
        }
        return (Math.floor(minutes % 60) + '分钟');
      }
      return (Math.floor(minutes / 60) + '小时');
    }
  }

  // 截取时间
  timesMDHD(key: string) {
    if (key !== undefined) {
      key = key.slice(5, 16);
    }
    return key;
  }

  // 排序 倒序
  sortarr(key, order) {
    return function(a, b) {
      a[key] == undefined ? a[key] = 0 :
        b[key] == undefined ? b[key] = 0 : 0;
      if (order == 'up') {
        return a[key] - b[key];
      } else if (order == 'down') {
        return b[key] - a[key];
      }
    };
  }

  //  父组件调用子组件函数
  getCheck() {
    this.getSingleData(this.carNum, this.JCID);
    this.remarkData = [];
    this.tracking = undefined;
    // 调用子组件 panel
    let childData = this.childCmps['_results'];
    for (let i = 0, len = childData.length; i < len; i++) {
      childData[i].getFun(this.CheckId, this.carNum, this.mdid, this.jd);
    }
    // 调用子组件 minutia
    let childList = this.childMinutia['_results'];
    for (let i = 0, len = childList.length; i < len; i++) {
      childList[i].getFun(this.CheckId, this.carNum, this.mdid, this.jd);
    }
    this.getTracking(this.CheckId);
    this.getComment(this.rightList['JCID']);
    this.getIcon();
    this.setClearTime();
  }

  /* 虚拟触发事件相关 */
  private $(id) {
    return document.getElementById(id);
  }

  getFocus(id) {
    // console.log(id+".focus");
  }

  getRightList(data: any) {
    this.rightData = JSON.stringify(data);
    this.rightList = data;
    this.CheckId = data.JJCDH;
    this.carIcon = data.TPLJ;
    this.carNum = data.CPHM;
    this.mdid = data.MDID;
    this.JCID = data.JCID;
    this.jd = data.JD;
    this.getCheck();
  }

  // 虚拟按键触发
  virtualKeyDown($event: any, data: any, click?: any) {
    $event.preventDefault();
    let key = $event.keyCode;
    if (click === 1) {
      key = 13;
    } else if (click === 2) {
      key = 0;
    }
    let id = Number($event.target.id);
    let nextId;

    switch (key) {
      case 0:
        if (this.keyNum > 0) {
          this.onDblClick();
        } else {
          this.onClick();
        }
        break;
      case 13:
        this.getRightList(data);
        break;
      case 38:
        if (id <= 0) {
          nextId = this.reportData[0].length - 1;
        } else {
          nextId = id - 1;
        }
        this.$(nextId).focus();
        break;
      case 40:
        if (id >= this.reportData[0].length - 1) {
          nextId = 0;
        } else {
          nextId = id + 1;
        }
        this.$(nextId).focus();
        break;
      case 37:
      case 27:
        if (this.tablesIndex <= 0) {
          this.tablesIndex = this.reportData.length;
        }
        this.tablesIndex--;
        this.getRightList(this.reportData[this.tablesIndex][0]);
        break;
      case 39:
      case 66:
        if (this.tablesIndex === this.reportData.length - 1) {
          this.tablesIndex = -1;
        }
        this.tablesIndex++;
        this.getRightList(this.reportData[this.tablesIndex][0]);
        break;
    }
  }

  // 脑袋数据
  setRightData() {
    return [
      {
        rightList: [
          { lable: '项目', feild: 'FWLXMC' },
          { lable: '定损进度', feild: 'DSJDMC' },
          { lable: '配件进度', feild: 'PJJDMC' },
          { lable: '年审进度', feild: 'NSJDMC' },
          { lable: '车在哪', feild: 'CARPLACEMC' },
          { lable: '返修车', feild: 'FXCMC' },
        ],
      },
    ];
  }

  // 综合评论获取
  getComment(JCID: string) {
    this.review = [];
    let data = { 'interfaceMethod': 'ipmCLZKForAppService.qryCarcontrolYY', 'pdata': { 'JCID': JCID } };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            data = data.sort(this.sortarr('LRRQ_SJ', 'down'));
            if (data.length <= 0) {
              this.review = [{ 'JLYY': '点击录入备注', 'JLRMC': '录入人', 'LRRQ_SJ': 0 }];
            } else {
              this.review = data;
            }
            this.remarkData = this.pageRemark(this.review, 2);
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  // 服务跟踪获取
  getTracking(JJCDH: string) {
    if (this.jd !== '年审中') {
      let data = { 'interfaceMethod': 'ipmCLZKForAppService.qryFWGZ', 'pdata': { 'JJCDH': JJCDH } };
      this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
        (resultData) => {
          const result = JSON.parse(resultData);
          if (result.success) {
            if (result.obj.length !== 0) {
              let data = JSON.parse(result.obj);
              data = data.sort(this.sortarr('KSSG', 'up'));
              for (let i = 0, len = data.length; i < len; i++) {
                data[i]['XH'] = i + 1;
                if (data[i]['KSSG'] == 0) {
                  data[i]['KSSG'] = undefined;
                }
              }
              data = data.sort(this.sortarr('XH', 'down'));
              this.tracking = data;
            }
          } else {
            this.msg.info(result.msg);
          }
        });
    }
  }

  onClick() {
    clearTimeout(this.clickTime);
    this.keyNum++;
    this.clickTime = setTimeout(() => {
      this.keyNum = 0;
      this.router.navigateByUrl('/analysis/control/index');
    }, 500);
  }

  onDblClick() {
    clearTimeout(this.clickTime);
    this.child.isVisible = true;
    this.keyNum = 0;
  }

  // 左侧列表单条数据刷新
  getSingleData(carNum: string, JCID: string) {
    let data = {
      'interfaceMethod': 'ipmCLZKForAppService.getLeftTotal', 'pdata': { 'CPHM': carNum, 'JCID': JCID },
    };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            let array = this.reportData[this.tablesIndex];
            for (let i = 0, len = array.length; i < len; i++) {
              if (array[i]['CPHM'] === data[0]['CPHM'] && array[i]['JCID'] === data[0]['JCID']) {
                this.reportData[this.tablesIndex][i] = data[0];
                setTimeout(() => {
                  this.$(i).focus();
                }, 0);
              }
            }
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  cryData = [
    { api: 'ipmCLZKForAppService.getDSJDDetails' },     // 定损方案
    { api: 'ipmCLZKForAppService.qryJDDetail' },        // 服务方案
  ];

  cryDataThree = [
    { api: 'ipmCLZKForAppService.qryGDJDHEAD' },      // 服务工单
  ];

  carDataTwo = [
    { api: 'ipmCLZKForAppService.qryCJHead' },         // 拆检
    { api: 'ipmCLZKForAppService.qryZDHead' },         // 诊断
    { api: 'ipmCLZKForAppService.qryPJBJ' },          // 配件报价
    { api: 'ipmCLZKForAppService.qryYHGZ' },          // 要货跟踪
    //
  ];
  carDataFri = [
    { api: 'ipmCLZKForAppService.getNSJDDetails', lable: '年审中' },   // 年审
  ];

  cryDataFour = [
    { api: 'ipmCLZKForAppService.qryNXHEAD' },         // 内协调度
    { api: 'ipmCLZKForAppService.qryWJSJC' },         // 未结算交车
    { api: 'ipmCLZKForAppService.getZJHEAD' },        // 质检
    { api: 'ipmCLZKForAppService.qryDSK' },           // 收款
  ];

  cryDataOne = [
    { api: 'ipmCLZKForAppService.qryWLPS' },          // 物流配送
    { api: 'ipmCLZKForAppService.qryZZZ' },           // 中转站
    { api: 'ipmCLZKForAppService.qryXDD' },           // 下订单
  ];

  //显示时间 天/小时   小时/分钟  分钟
  toHour(minutes) {
    if (Math.floor(minutes / 60 / 24) >= 1) {
      return (Math.floor(minutes / 60 / 24) + '天' + Math.floor(minutes / 60 % 24) + '时');
    } else if (Math.floor(minutes / 60 / 24) < 1) {
      if (Math.floor(minutes) < 60) {
        return (Math.floor(minutes % 60) + '分');
      }
      if (Math.floor(minutes % 60) === 0) {
        return (Math.floor(minutes / 60) + '时');
      }
      return (Math.floor(minutes / 60) + '时' + Math.floor(minutes % 60) + '分');
    }
  }

  timeChange(time: number) {
    let day;
    if (time !== undefined) {
      day = this.datePipe.transform(new Date(time),
        'yyyy-MM-dd HH:mm:ss').slice(5, 16);
      return day;
    }
  }

  /*****
   * 2019-9-2
   * 新增搜索功能 、 录入备注功能 （抽屉方式滑出）
   * 1、（右侧搜索抽屉） carVisible 、queryList、 carOpen() 、 carClose()、 carGetNewInfo()、 getQueryHead(company)
   *      carClean()、 radioValue 、 carQuery() 、pickCarTime 、carStartTime、 carEndTime、 getDate()、 carNumber、carStatus
   *      carStatusId、 carStoreId、 carStore、 damage、 damageId、 carBrands、 checkOne 、checkTwo、 checkThe 、checkFro
   *      getStoreData()、getDamageData()、
   * （左侧录入抽屉） entryVisible 、 entryOpen() 、 entryClose()、 entryGetNewInfo() 、setReview 、setComment()、 getComment()
   * ******/
  carOpen() {
    this.carVisible = true;
  }

  carClose() {
    this.carVisible = false;
  }

  getQueryHead() {           // 获取 查询头部
    let data = { 'interfaceMethod': 'ipmCLZKForAppService.getClzkHead', 'pdata': { 'companyId': this.companyData } };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            for (let i in data) {
              if (data[i]['TITLE'] === '待到店') {
                data.splice(i, 1);
              }
            }
            this.queryList = data;
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  carClean() {
    this.radioValue = 'CarInTV';
    this.checkOne = false;
    this.checkTwo = false;
    this.checkThe = false;
    this.checkFro = false;
    this.carBrands = undefined;
    this.damageId = undefined;
    this.carStoreId = undefined;
    this.carStatusId = undefined;
    this.carNumber = undefined;
    this.pickCarTime = [];
  }

  carQuery() {
    this.carVisible = false;
    this.tablesIndex = 0;
    this.reportData = [];
    this.allData = [];
    this.getDate(this.pickCarTime, 'carStartTime', 'carEndTime');
    this.getLeftData();
  }

  getDate(time: any[], time_ks: string, time_js: string) {
    let [first, second] = time;
    if (first) {
      this[time_ks] = first.toISOString().slice(0, 10);
    } else {
      this[time_ks] = null;
    }

    if (second) {
      this[time_js] = second.toISOString().slice(0, 10);
    } else {
      this[time_js] = null;
    }

  }

  getStoreData() {    // 获取门店名称
    let data = { 'interfaceMethod': 'ipmBPforAppService.getSQMDXX', 'pdata': {'companyId': this.companyData} };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            this.carStore = data;
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  getDamageData() {        // 获取 定损进度
    let data = { 'interfaceMethod': 'ipmCLZKForAppService.getDsjd', 'pdata': {} };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            this.damage = data;
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  carStatus = [
    { label: '检测中', key: 1 },
    { label: '定损中', key: 2 },
    { label: '待方案提交', key: 26 },
    { label: '待配件报价', key: 21 },
    { label: '待技术审核', key: 20 },
    { label: '待价格审核', key: 22 },
    { label: '待方案确认', key: 3 },
    { label: '等货中', key: 4 },
    // {label: "基地等货中", key: 5},
    { label: '待施工', key: 6 },
    // {label: "基地待施工", key: 7},
    { label: '待基地接车', key: 8 },
    // {label: "施工暂停", key: 27},
    // {label: "本店施工中", key: 10},
    { label: '施工中', key: 9 },
    { label: '待外协派工', key: 23 },
    { label: '外协施工中', key: 24 },
    { label: '待基地还车', key: 11 },
    { label: '待质检', key: 12 },
    { label: '待收款', key: 13 },
    { label: '待催款', key: 19 },
    { label: '待交车', key: 14 },
    { label: '待到店施工', key: 17 },
    // {label: "待到店施工，货已到", key: 18},
    { label: '年审中', key: 25 },
    { label: '拆检中', key: 29 },
    { label: '待门店收车', key: 28 },
  ];

  entryOpen() {
    this.entryVisible = true;
  }

  entryClose() {
    this.entryVisible = false;
    this.setReview = undefined;
  }

  setComment() {   // 保存 综合评论
    let data = {
      'interfaceMethod': 'ipmCLZKForAppService.exec_carcomtrolYY',
      'pdata': {
        'CZBJ': 0, 'JCID': this.JCID, 'CPHM': this.carNum, 'JLRID': this.userInfo.userAccount.userId,
        'JLRMC': this.userInfo.userAccount.name, 'JLYY': this.setReview,
      },
    };
    this.apiService.post('report.interface', { 'body': JSON.stringify(data) }).subscribe(
      (resultData) => {
        const result = JSON.parse(resultData);
        if (result.success) {
          if (result.obj.length !== 0) {
            let data = JSON.parse(result.obj);
            // console.log(data)
            this.msg.info('保存成功');
            this.getComment(this.JCID);
            this.setReview = undefined;
          }
        } else {
          this.msg.info(result.msg);
        }
      });
  }

  entryGetNewInfo() {
    this.entryVisible = false;
    this.setComment();
  }

  ngOnDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
    if (this.timers) {
      clearInterval(this.timers);
    }
    if (this.remarkTimers) {
      clearInterval(this.remarkTimers);
    }
  }

}
